<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        ul li{
            border-bottom: 1px solid #eee;
            cursor: pointer;
            margin: 0;
            padding: 0;
        }
    </style>
</head>
<body>
<script src="vue.js"></script>
<ul id="ul-list">
    <todo-item
            v-for="item in students"
            v-bind:item="item"
            v-bind:key="item.name">
    </todo-item>
    <li>
        <button v-on:click="addStudent">Add Student</button>
    </li>
</ul>
<script>
    //定义名为 todo-item 的新组件
    Vue.component('todo-item', {
        props: ['item'],
        template: '<li v-on:click="showInfo">name: {{ item.name }}, age: {{ item.age }}</li>',
        methods:{
            showInfo:function () {
                console.log(this);
            }
        },
    });
    // 创建根实例
    new Vue({
        el: '#ul-list',
        data: {
            students: [
                {name:"lzugis1",age:1},
                {name:"lzugis2",age:2},
                {name:"lzugis3",age:3},
                {name:"lzugis4",age:4}
            ]
        },
        methods:{
            addStudent: function () {
                this.students.push({name:"lzugis5",age:5});
            }
        },
        created: function () {
            console.log("Vue is created!");
        }
    });
</script>
</body>
</html>